package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.HelpVehicle;
import com.ruoyi.help.service.IHelpVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/help/vehicle")
public class HelpVehicleController extends BaseController
{
    @Autowired
    private IHelpVehicleService helpVehicleService;

    /**
     * 查询车辆列表
     */
    @PreAuthorize("@ss.hasPermi('help:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpVehicle helpVehicle)
    {
        startPage();
        List<HelpVehicle> list = helpVehicleService.selectHelpVehicleList(helpVehicle);
        return getDataTable(list);
    }

    /**
     * 导出车辆列表
     */
    @PreAuthorize("@ss.hasPermi('help:vehicle:export')")
    @Log(title = "车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpVehicle helpVehicle)
    {
        List<HelpVehicle> list = helpVehicleService.selectHelpVehicleList(helpVehicle);
        ExcelUtil<HelpVehicle> util = new ExcelUtil<HelpVehicle>(HelpVehicle.class);
        util.exportExcel(response, list, "车辆数据");
    }

    /**
     * 获取车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('help:vehicle:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return success(helpVehicleService.selectHelpVehicleByUId(uId));
    }

    /**
     * 新增车辆
     */
    @PreAuthorize("@ss.hasPermi('help:vehicle:add')")
    @Log(title = "车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HelpVehicle helpVehicle)
    {
        return toAjax(helpVehicleService.insertHelpVehicle(helpVehicle));
    }

    /**
     * 修改车辆
     */
    @PreAuthorize("@ss.hasPermi('help:vehicle:edit')")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HelpVehicle helpVehicle)
    {
        return toAjax(helpVehicleService.updateHelpVehicle(helpVehicle));
    }

    /**
     * 删除车辆
     */
    @PreAuthorize("@ss.hasPermi('help:vehicle:remove')")
    @Log(title = "车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(helpVehicleService.deleteHelpVehicleByUIds(uIds));
    }
}
